home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Kant Generator Pro 1.2 / src / Shell ƒ / environment.c < prev    next >
C/C++ Source or Header  |  1995-01-19  |  3KB  |  100 lines

  1. #include "environment.h"
  2. #include "apple events.h"
  3. #include "error.h"
  4. #include "program globals.h"
  5. #include "GestaltEqu.h"
  6. #include "Traps.h"
  7.  
  8. Boolean            gHasColorQD;                /* color Quickdraw present? */
  9. Boolean            gHasNotificationManager;    /* notification manager present? (cf error.c) */
  10.  
  11. short            gForegroundWaitTime;        /* WaitNextEvent sleep time while in frgrnd */
  12. short            gBackgroundWaitTime;        /* WaitNextEvent sleep time while in bkgrnd */
  13. Boolean            gIsInBackground;            /* program is in background currently? */
  14. Boolean            gInProgress;                /* progress bar up? */
  15. Boolean            gDone;                        /* program done? */
  16. short            gFrontWindowIndex;            /* gTheWindowData[] index of front window, if ours */
  17. Boolean            gIsVirgin;                    /* first time running? */
  18. Boolean            gCustomCursor;                /* front window is using custom cursor ? */
  19. short            gKludgeIter;
  20. Boolean            gNeedToOpenWindow;
  21.  
  22. #define        GESTALT_TRAP    0xA1AD            /* _Gestalt */
  23.  
  24. #define    GetTrapType(T)    (((T & 0x0800) > 0) ? ToolTrap : OSTrap)
  25. #define NumToolboxTraps()    ((NGetTrapAddress(_InitGraf, ToolTrap) ==    \
  26.                             NGetTrapAddress(0xAA6E, ToolTrap)) ? 0x0200    \
  27.                             : 0x0400)
  28.  
  29. Boolean MyTrapAvailable(short theTrap);
  30.  
  31. Boolean MyTrapAvailable(short theTrap)
  32. {
  33.     TrapType        tType;
  34.     
  35.     tType=GetTrapType(theTrap);
  36.     if (tType==ToolTrap)
  37.     {
  38.         theTrap=theTrap&0x07FF;
  39.         if (theTrap>=NumToolboxTraps())
  40.             theTrap=_Unimplemented;
  41.     }
  42.     return (NGetTrapAddress(theTrap, tType)!=NGetTrapAddress(_Unimplemented, ToolTrap));
  43. }
  44.  
  45. Boolean InitTheEnvironment(void)
  46. /* called very early -- this uses Gestalt to check out the computing environment;
  47.    see above for explanations of variables */
  48. {
  49.     long            gestalt_temp;
  50.     OSErr            isHuman;
  51.     SysEnvRec        theWorld;
  52.     
  53.     if (SysEnvirons(1, &theWorld)==envNotPresent)
  54.         return FALSE;
  55.     
  56.     if (!MyTrapAvailable(_WaitNextEvent))
  57.         return FALSE;
  58.     
  59.     if (!MyTrapAvailable((short)GESTALT_TRAP))
  60.         return FALSE;
  61.  
  62.     isHuman=Gestalt(gestaltSystemVersion, &gestalt_temp);
  63.     if (isHuman || (gestalt_temp < 1792))
  64.         return FALSE;
  65.     
  66.     isHuman=Gestalt(gestaltQuickdrawVersion, &gestalt_temp);
  67.     gHasColorQD=!(isHuman || (gestalt_temp < gestalt8BitQD));
  68.  
  69.     isHuman=Gestalt(gestaltFSAttr, &gestalt_temp);
  70.     if (!((isHuman==noErr) && (gestalt_temp&(1<<gestaltHasFSSpecCalls))))
  71.         return FALSE;
  72.  
  73.     isHuman=Gestalt(gestaltStandardFileAttr, &gestalt_temp);
  74.     if (!((isHuman==noErr) && (gestalt_temp&(1<<gestaltStandardFile58))))
  75.         return FALSE;
  76.  
  77.     isHuman=Gestalt(gestaltNotificationMgrAttr, &gestalt_temp);
  78.     gHasNotificationManager=(!((isHuman) ||
  79.         (((gestalt_temp >> gestaltNotificationPresent) & 0x01) != 1)));
  80.     
  81.     isHuman=Gestalt(gestaltAppleEventsAttr, &gestalt_temp);
  82.     if (!((!isHuman) && (gestalt_temp&(1<<gestaltAppleEventsPresent))))
  83.         return FALSE;
  84.     
  85.     InstallRequiredAppleEvents();
  86.     
  87.     gForegroundWaitTime=0;            /* WaitNextEvent sleep time when we're in frgrnd */
  88.     gBackgroundWaitTime=100;        /* WaitNextEvent sleep time when we're in bkgrnd */
  89.     gDone=FALSE;                    /* TRUE if program is done (exit event loop) */
  90.     gInProgress=FALSE;                /* TRUE if progress bar is up */
  91.     gIsInBackground=FALSE;            /* TRUE if program is in background */
  92.     gPendingErrorRec.resultCode=allsWell;
  93.     gFrontWindowIndex=0;
  94.     gCustomCursor=FALSE;
  95.     gKludgeIter=0;
  96.     gNeedToOpenWindow=TRUE;
  97.  
  98.     return TRUE;
  99. }
  100.